<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        document.addEventListener('keyup', function (e) {
            // console.log(e);
            console.log('up:' + e.keyCode);

            //我们的keyup和keydown事件不区分大小写 a和A都是65
            //keypress区分大小写
            //我们可以根据keyCode的ASCII码值来判断用户按下哪个键
            if (e.keyCode === 65) {
                alert('您按下了a')
            } else {
                alert('您没有按下a键')
            }


        })


        document.addEventListener('keypress', function (e) {
            // console.log(e);
            console.log('press:' + e.keyCode);
            //keypress区分大小写

        })
    </script>
</body>

</html>